num=int(input())
if 10000>num>999:
    a=num%10
    b=num%100//10
    c=num//100%10
    d=num//1000
    mmm=[num,a,b,c,d]
    mmm.append(b*10+a)
    mmm.append(c*10+b)
    mmm.append(d*10+c)
    mmm.append(d*100+c*10+b)
    mmm.append(c*100+b*10+a)
    mama=[0]
    for x in mmm:
        count=0
        for i in range(2,x):
            if x%i==0:
                count+=1
        if count==0:
            mama.append(x)
    print(max(mama))       
else:
    print(0)
    exit()
